package com.tl.commonlibrary.ui.beans;

import android.content.Context;

import com.tl.commonlibrary.storage.configuration.PrefUtil;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created by JongSung on 18/3/6.
 */

public class ExerciseListBean implements Serializable {
    /**
     * 试卷来源
     */

    public static final int TYPE_RESULT_SUBJECTIVE_SCORE = 7;//自评分
    public static final int TYPE_RESULT_ALL_ANALYSIS = 6;//所有解析
    public static final int TYPE_RESULT_WRONG_ANSWER_ANALYSIS = 5;//错题解析
    public static final int TYPE_EXERCISE_HISTORY = 4;//答题记录
    public static final int TYPE_WRONG_ANSWER = 3;//错题
    public static final int TYPE_COLLECTION = 2;//收藏
    public static final int TYPE_TRAIL = 1;//试用
    public static final int TYPE_ALL = 0;//所有
    /**
     * 购买状态说明 1 试用 2 已购买 3 免费使用
     */
    public static final int STATUS_FREE = 3;
    public static final int STATUS_PURCHASED = 2;
    public static final int STATUS_ON_TRAIL = 1;
    /**
     * 试卷考试类型
     */
    public static final int METHOD_PRACTICE = 1;//练习类型
    public static final int METHOD_EXAMINATION = 2;//考试类型
    private long pUserSummaryId;
    private long paperId;
    private int itemTotal;
    private int method;
    private double price;
    private String paperTitle;
    private ArrayList<ExerciseBean> paperItems;
    private int status;

    /**
     * 考试提交答案后的一些属性
     *
     * @return
     */
    private double multiChoiceScore;
    private double singleChoiceScore;
    private double shortAnswerScore;
    private double analysisQuestScore;//综合分析题总得分
    private double calcQuestScore;//计算题总得分
    private double officialDocScore;//公文筐检测总得分
    private double totalScore;
    private double trueOrFalseScore;

    public long getpUserSummaryId() {
        return pUserSummaryId;
    }

    public void setpUserSummaryId(long pUserSummaryId) {
        this.pUserSummaryId = pUserSummaryId;
    }

    public long getPaperId() {
        return paperId;
    }

    public void setPaperId(long paperId) {
        this.paperId = paperId;
    }

    public ArrayList<ExerciseBean> getPaperItems() {
        return paperItems;
    }

    public void setPaperItems(ArrayList<ExerciseBean> paperItems) {
        this.paperItems = paperItems;
    }

    public void resetPaperItems(ArrayList<ExerciseBean> paperItems) {
        if (this.paperItems != null) {
            this.paperItems.clear();
        }
        this.paperItems = new ArrayList<>();
        this.paperItems.addAll(paperItems);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isStatusOnTrail() {
        return status == STATUS_ON_TRAIL;
    }

    public boolean isStatusPurchased() {
        return status == STATUS_PURCHASED;
    }

    public boolean isStatusFree() {
        return status == STATUS_FREE;
    }


    public boolean hasExercise() {
        return paperItems != null && !paperItems.isEmpty();
    }

    public boolean isMethodPractice() {
        return method == METHOD_PRACTICE;
    }

    public boolean isMethodExamination() {
        return method == METHOD_EXAMINATION;
    }

    public int getItemTotal() {
        return itemTotal;
    }

    public void setItemTotal(int itemTotal) {
        this.itemTotal = itemTotal;
    }

    public int getMethod() {
        return method;
    }

    public void setMethod(int method) {
        this.method = method;
    }

    public double getMultiChoiceScore() {
        return multiChoiceScore;
    }

    public void setMultiChoiceScore(double multiChoiceScore) {
        this.multiChoiceScore = multiChoiceScore;
    }

    public double getSingleChoiceScore() {
        return singleChoiceScore;
    }

    public void setSingleChoiceScore(double singleChoiceScore) {
        this.singleChoiceScore = singleChoiceScore;
    }

    public double getShortAnswerScore() {
        return shortAnswerScore;
    }

    public void setShortAnswerScore(double shortAnswerScore) {
        this.shortAnswerScore = shortAnswerScore;
    }

    public double getSubjectiveScore() {
        return this.shortAnswerScore + this.analysisQuestScore + this.calcQuestScore + this.officialDocScore;
    }
    public void setSubjectvieScore(){
    }

    public double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(double totalScore) {
        this.totalScore = totalScore;
    }

    public double getTrueOrFalseScore() {
        return trueOrFalseScore;
    }

    public void setTrueOrFalseScore(double trueOrFalseScore) {
        this.trueOrFalseScore = trueOrFalseScore;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getPaperTitle() {
        return paperTitle;
    }

    public void setPaperTitle(String paperTitle) {
        this.paperTitle = paperTitle;
    }

    public double getAnalysisQuestScore() {
        return analysisQuestScore;
    }

    public void setAnalysisQuestScore(double analysisQuestScore) {
        this.analysisQuestScore = analysisQuestScore;
    }

    public double getCalcQuestScore() {
        return calcQuestScore;
    }

    public void setCalcQuestScore(double calcQuestScore) {
        this.calcQuestScore = calcQuestScore;
    }

    public double getOfficialDocScore() {
        return officialDocScore;
    }

    public void setOfficialDocScore(double officialDocScore) {
        this.officialDocScore = officialDocScore;
    }

    public int getExerciseSize() {
        if (hasExercise()) {
            return paperItems.size();
        }
        return 0;
    }

    public static void startTime(Context context) {
        PrefUtil prefUtil = new PrefUtil(context);
        prefUtil.putLong("ExerciseStartTime", System.currentTimeMillis());
        prefUtil.remove("ExerciseEndTime");
    }

    public static void endTime(Context context) {
        new PrefUtil(context).putLong("ExerciseEndTime", System.currentTimeMillis());
    }

    public static void resetTime(Context context) {
        PrefUtil prefUtil = new PrefUtil(context);
        prefUtil.remove("ExerciseStartTime");
        prefUtil.remove("ExerciseEndTime");
    }

    public static long getExerciseTime(Context context) {
        PrefUtil prefUtil = new PrefUtil(context);
        long startTime = prefUtil.getLong("ExerciseStartTime", 0);
        long endTime = prefUtil.getLong("ExerciseEndTime", 0);
        return endTime - startTime;
    }

    public static String getExerciseTimeFormat(Context context) {
        long time = getExerciseTime(context);
        long seconds = time / 1000;
        long hour = seconds / 3600;
        seconds %= 3600;
        long minute = seconds / 60;
        seconds %= 60;
        long second = seconds;
        return (hour >= 10 ? "" + hour : ("0" + hour)) + ":" + (minute >= 10 ? "" + minute : "0" + minute) + ":" + (second >= 10 ? "" + second : "0" + second);
    }
}
